package cn.itcast.user.service.impl;

import cn.itcast.hmall.dto.common.ThreadLocalUtil;
import cn.itcast.hmall.pojo.user.Address;
import cn.itcast.user.mapper.AddressMapper;
import cn.itcast.user.service.AddressService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 哈纳桑
 * @since 2024-07-13
 */
@Service
public class AddressServiceImpl extends ServiceImpl<AddressMapper, Address> implements AddressService {

    /**
     * 根据用户id查询地址列表
     * @return
     */
    @Override
    public List<Address> getAddressList() {

        //1.获取用户id
        Long userId = ThreadLocalUtil.getUserId();

        //2.根据用户id查询地址列表
        LambdaQueryWrapper<Address> wrapper = new LambdaQueryWrapper<Address>()
                .eq(Address::getUserId, userId);

        List<Address> addressList = list(wrapper);

        return addressList;
    }


}
